package baseline;

import java.util.Vector;

public class WordStat {
  public static class TagStat {
    String tag_;
    int count_;

    TagStat(String tag) {
      tag_ = tag;
      count_ = 1;
    }

    void incCount() {
      count_++;
    }

    String getTag() {
      return tag_;
    }

    int getCount() {
      return count_;
    }
  }

  Vector<TagStat> stats_;
  String bestTag_;

  public WordStat(String tag) {
    stats_ = new Vector<WordStat.TagStat>();

    TagStat ts = new TagStat(tag);
    stats_.add(ts);
  }

  public void addTag(String tagToAdd) {
    boolean found = false;

    for (int i = 0; i < stats_.size(); ++i) {
      TagStat ts = stats_.get(i);

      if (ts.getTag().equals(tagToAdd)) {
        ts.incCount();
        found = true;
        break;
      }
    }

    if (found == false) {
      TagStat ts = new TagStat(tagToAdd);
      stats_.add(ts);
    }
  }

  public void process() {
    int maxTagIndex = 0, maxCount = -1;
    for (int i = 0; i < stats_.size(); ++i) {
      if (stats_.get(i).getCount() > maxCount) {
        maxCount = stats_.get(i).getCount();
        maxTagIndex = i;
      }
    }

    bestTag_ = stats_.get(maxTagIndex).getTag();
    stats_.clear();
  }

  public String getBestTag() {
    return bestTag_;
  }
}